package org.bbmall.controller;

import lombok.RequiredArgsConstructor;
import org.bbmall.bean.Result;
import org.bbmall.dto.member.MemberDashboardDataDTO;
import org.bbmall.dto.sales.SalesDashboardDataDTO;
import org.bbmall.dto.store.StoreDashboardDataDTO;
import org.bbmall.service.IAnalysisService;
import org.bbmall.service.IMemberAnalysisService;
import org.bbmall.service.IStoreAnalysisService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * 超市数据分析系统前端controller
 */
@RestController
@RequestMapping("/api/analysis")
@RequiredArgsConstructor
public class AnalysisController {

    private final IAnalysisService analysisService;

    private final IMemberAnalysisService memberAnalysisService;

    private final IStoreAnalysisService storeAnalysisService;

    /**
     * 获取销售分析仪表板所有数据
     * @return 包含所有界面数据的DTO对象
     */
    @GetMapping("/salesInfo")
    public Result getSaleInfoDashboardData(@RequestParam(required = false) String dateTime) {
        LocalDate date = LocalDate.parse(dateTime);
        SalesDashboardDataDTO dashboardData = analysisService.getDashboardData(date);
        Result res = new Result();
        res.setSuccess(true);
        res.setData(dashboardData);
        return res;
    }




    /**
     * 获取会员分析仪表板所有数据
     * @return 包含所有会员分析数据的DTO对象
     */
    @GetMapping("/memberInfo")
    public Result getMemberDashboardData(@RequestParam(required = false) String dateTime) {
        LocalDate date = LocalDate.parse(dateTime);
        MemberDashboardDataDTO memberDashboardData = memberAnalysisService.getMemberDashboardData(date);
        Result res = new Result();
        res.setSuccess(true);
        res.setData(memberDashboardData);
        return res;
    }




    /**
     * 获取商店分析仪表板所有数据
     * @return 包含所有商店分析数据的DTO对象
     */
    @GetMapping("/storeInfo")
    public Result getStoreDashboardData(@RequestParam(required = false) String dateTime) {
        LocalDate date = LocalDate.parse(dateTime);
        StoreDashboardDataDTO storeDashboardData = storeAnalysisService.getStoreDashboardData(date);
        Result res = new Result();
        res.setSuccess(true);
        res.setData(storeDashboardData);
        return res;
    }

}